package cesdentalrecord.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Mon Mar 22 12:41:25 CST 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Total
 */
public abstract class BaseTotal extends BaseObject
{
    /** The Peer class */
    private static final TotalPeer peer =
        new TotalPeer();

        
    /** The value for the teethtotalID field */
    private int teethtotalID;
      
    /** The value for the studentID field */
    private int studentID;
      
    /** The value for the totalPerm field */
    private int totalPerm;
      
    /** The value for the totalSound field */
    private int totalSound;
      
    /** The value for the totalDecayed field */
    private int totalDecayed;
      
    /** The value for the totalMissing field */
    private int totalMissing;
      
    /** The value for the totalFilled field */
    private int totalFilled;
      
    /** The value for the totalDFM field */
    private int totalDFM;
      
    /** The value for the totalTemp field */
    private int totalTemp;
      
    /** The value for the totalTempSound field */
    private int totalTempSound;
      
    /** The value for the totalTempDecayed field */
    private int totalTempDecayed;
      
    /** The value for the totalTempFilled field */
    private int totalTempFilled;
      
    /** The value for the totalTempDFM field */
    private int totalTempDFM;
      
    /** The value for the examDate field */
    private String examDate;
  
    
    /**
     * Get the TeethtotalID
     *
     * @return int
     */
    public int getTeethtotalID()
    {
        return teethtotalID;
    }

                        
    /**
     * Set the value of TeethtotalID
     *
     * @param v new value
     */
    public void setTeethtotalID(int v) 
    {
    
                  if (this.teethtotalID != v)
              {
            this.teethtotalID = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the StudentID
     *
     * @return int
     */
    public int getStudentID()
    {
        return studentID;
    }

                              
    /**
     * Set the value of StudentID
     *
     * @param v new value
     */
    public void setStudentID(int v) throws TorqueException
    {
    
                  if (this.studentID != v)
              {
            this.studentID = v;
            setModified(true);
        }
    
                          
                if (aStudent != null && !(aStudent.getStudentID() == v))
                {
            aStudent = null;
        }
      
              }
  
    /**
     * Get the TotalPerm
     *
     * @return int
     */
    public int getTotalPerm()
    {
        return totalPerm;
    }

                        
    /**
     * Set the value of TotalPerm
     *
     * @param v new value
     */
    public void setTotalPerm(int v) 
    {
    
                  if (this.totalPerm != v)
              {
            this.totalPerm = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalSound
     *
     * @return int
     */
    public int getTotalSound()
    {
        return totalSound;
    }

                        
    /**
     * Set the value of TotalSound
     *
     * @param v new value
     */
    public void setTotalSound(int v) 
    {
    
                  if (this.totalSound != v)
              {
            this.totalSound = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalDecayed
     *
     * @return int
     */
    public int getTotalDecayed()
    {
        return totalDecayed;
    }

                        
    /**
     * Set the value of TotalDecayed
     *
     * @param v new value
     */
    public void setTotalDecayed(int v) 
    {
    
                  if (this.totalDecayed != v)
              {
            this.totalDecayed = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalMissing
     *
     * @return int
     */
    public int getTotalMissing()
    {
        return totalMissing;
    }

                        
    /**
     * Set the value of TotalMissing
     *
     * @param v new value
     */
    public void setTotalMissing(int v) 
    {
    
                  if (this.totalMissing != v)
              {
            this.totalMissing = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalFilled
     *
     * @return int
     */
    public int getTotalFilled()
    {
        return totalFilled;
    }

                        
    /**
     * Set the value of TotalFilled
     *
     * @param v new value
     */
    public void setTotalFilled(int v) 
    {
    
                  if (this.totalFilled != v)
              {
            this.totalFilled = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalDFM
     *
     * @return int
     */
    public int getTotalDFM()
    {
        return totalDFM;
    }

                        
    /**
     * Set the value of TotalDFM
     *
     * @param v new value
     */
    public void setTotalDFM(int v) 
    {
    
                  if (this.totalDFM != v)
              {
            this.totalDFM = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalTemp
     *
     * @return int
     */
    public int getTotalTemp()
    {
        return totalTemp;
    }

                        
    /**
     * Set the value of TotalTemp
     *
     * @param v new value
     */
    public void setTotalTemp(int v) 
    {
    
                  if (this.totalTemp != v)
              {
            this.totalTemp = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalTempSound
     *
     * @return int
     */
    public int getTotalTempSound()
    {
        return totalTempSound;
    }

                        
    /**
     * Set the value of TotalTempSound
     *
     * @param v new value
     */
    public void setTotalTempSound(int v) 
    {
    
                  if (this.totalTempSound != v)
              {
            this.totalTempSound = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalTempDecayed
     *
     * @return int
     */
    public int getTotalTempDecayed()
    {
        return totalTempDecayed;
    }

                        
    /**
     * Set the value of TotalTempDecayed
     *
     * @param v new value
     */
    public void setTotalTempDecayed(int v) 
    {
    
                  if (this.totalTempDecayed != v)
              {
            this.totalTempDecayed = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalTempFilled
     *
     * @return int
     */
    public int getTotalTempFilled()
    {
        return totalTempFilled;
    }

                        
    /**
     * Set the value of TotalTempFilled
     *
     * @param v new value
     */
    public void setTotalTempFilled(int v) 
    {
    
                  if (this.totalTempFilled != v)
              {
            this.totalTempFilled = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the TotalTempDFM
     *
     * @return int
     */
    public int getTotalTempDFM()
    {
        return totalTempDFM;
    }

                        
    /**
     * Set the value of TotalTempDFM
     *
     * @param v new value
     */
    public void setTotalTempDFM(int v) 
    {
    
                  if (this.totalTempDFM != v)
              {
            this.totalTempDFM = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the ExamDate
     *
     * @return String
     */
    public String getExamDate()
    {
        return examDate;
    }

                        
    /**
     * Set the value of ExamDate
     *
     * @param v new value
     */
    public void setExamDate(String v) 
    {
    
                  if (!ObjectUtils.equals(this.examDate, v))
              {
            this.examDate = v;
            setModified(true);
        }
    
          
              }
  
      
    
                  
    
        private Student aStudent;

    /**
     * Declares an association between this object and a Student object
     *
     * @param v Student
     * @throws TorqueException
     */
    public void setStudent(Student v) throws TorqueException
    {
            if (v == null)
        {
                    setStudentID(0);
                  }
        else
        {
            setStudentID(v.getStudentID());
        }
                aStudent = v;
    }

                                            
    /**
     * Get the associated Student object
     *
     * @return the associated Student object
     * @throws TorqueException
     */
    public Student getStudent() throws TorqueException
    {
        if (aStudent == null && (this.studentID > 0))
        {
                          aStudent = StudentPeer.retrieveByPK(SimpleKey.keyFor(this.studentID));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Student obj = StudentPeer.retrieveByPK(this.studentID);
               obj.addTotals(this);
            */
        }
        return aStudent;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setStudentKey(ObjectKey key) throws TorqueException
    {
      
                        setStudentID(((NumberKey) key).intValue());
                  }
       
                
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("TeethtotalID");
              fieldNames.add("StudentID");
              fieldNames.add("TotalPerm");
              fieldNames.add("TotalSound");
              fieldNames.add("TotalDecayed");
              fieldNames.add("TotalMissing");
              fieldNames.add("TotalFilled");
              fieldNames.add("TotalDFM");
              fieldNames.add("TotalTemp");
              fieldNames.add("TotalTempSound");
              fieldNames.add("TotalTempDecayed");
              fieldNames.add("TotalTempFilled");
              fieldNames.add("TotalTempDFM");
              fieldNames.add("ExamDate");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("TeethtotalID"))
        {
                return new Integer(getTeethtotalID());
            }
          if (name.equals("StudentID"))
        {
                return new Integer(getStudentID());
            }
          if (name.equals("TotalPerm"))
        {
                return new Integer(getTotalPerm());
            }
          if (name.equals("TotalSound"))
        {
                return new Integer(getTotalSound());
            }
          if (name.equals("TotalDecayed"))
        {
                return new Integer(getTotalDecayed());
            }
          if (name.equals("TotalMissing"))
        {
                return new Integer(getTotalMissing());
            }
          if (name.equals("TotalFilled"))
        {
                return new Integer(getTotalFilled());
            }
          if (name.equals("TotalDFM"))
        {
                return new Integer(getTotalDFM());
            }
          if (name.equals("TotalTemp"))
        {
                return new Integer(getTotalTemp());
            }
          if (name.equals("TotalTempSound"))
        {
                return new Integer(getTotalTempSound());
            }
          if (name.equals("TotalTempDecayed"))
        {
                return new Integer(getTotalTempDecayed());
            }
          if (name.equals("TotalTempFilled"))
        {
                return new Integer(getTotalTempFilled());
            }
          if (name.equals("TotalTempDFM"))
        {
                return new Integer(getTotalTempDFM());
            }
          if (name.equals("ExamDate"))
        {
                return getExamDate();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(TotalPeer.TEETHTOTALID))
        {
                return new Integer(getTeethtotalID());
            }
          if (name.equals(TotalPeer.STUDENTID))
        {
                return new Integer(getStudentID());
            }
          if (name.equals(TotalPeer.TOTALPERM))
        {
                return new Integer(getTotalPerm());
            }
          if (name.equals(TotalPeer.TOTALSOUND))
        {
                return new Integer(getTotalSound());
            }
          if (name.equals(TotalPeer.TOTALDECAYED))
        {
                return new Integer(getTotalDecayed());
            }
          if (name.equals(TotalPeer.TOTALMISSING))
        {
                return new Integer(getTotalMissing());
            }
          if (name.equals(TotalPeer.TOTALFILLED))
        {
                return new Integer(getTotalFilled());
            }
          if (name.equals(TotalPeer.TOTALDMF))
        {
                return new Integer(getTotalDFM());
            }
          if (name.equals(TotalPeer.TOTALTEMP))
        {
                return new Integer(getTotalTemp());
            }
          if (name.equals(TotalPeer.TOTALTEMPSOUND))
        {
                return new Integer(getTotalTempSound());
            }
          if (name.equals(TotalPeer.TOTALTEMPDECAYED))
        {
                return new Integer(getTotalTempDecayed());
            }
          if (name.equals(TotalPeer.TOTALTEMPFILLED))
        {
                return new Integer(getTotalTempFilled());
            }
          if (name.equals(TotalPeer.TOTALTEMPDMF))
        {
                return new Integer(getTotalTempDFM());
            }
          if (name.equals(TotalPeer.EXAMDATE))
        {
                return getExamDate();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getTeethtotalID());
            }
              if (pos == 1)
        {
                return new Integer(getStudentID());
            }
              if (pos == 2)
        {
                return new Integer(getTotalPerm());
            }
              if (pos == 3)
        {
                return new Integer(getTotalSound());
            }
              if (pos == 4)
        {
                return new Integer(getTotalDecayed());
            }
              if (pos == 5)
        {
                return new Integer(getTotalMissing());
            }
              if (pos == 6)
        {
                return new Integer(getTotalFilled());
            }
              if (pos == 7)
        {
                return new Integer(getTotalDFM());
            }
              if (pos == 8)
        {
                return new Integer(getTotalTemp());
            }
              if (pos == 9)
        {
                return new Integer(getTotalTempSound());
            }
              if (pos == 10)
        {
                return new Integer(getTotalTempDecayed());
            }
              if (pos == 11)
        {
                return new Integer(getTotalTempFilled());
            }
              if (pos == 12)
        {
                return new Integer(getTotalTempDFM());
            }
              if (pos == 13)
        {
                return getExamDate();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(TotalPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    TotalPeer.doInsert((Total) this, con);
                    setNew(false);
                }
                else
                {
                    TotalPeer.doUpdate((Total) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }


                    
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  teethtotalID ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setTeethtotalID(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setTeethtotalID(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getTeethtotalID());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public Total copy() throws TorqueException
    {
        return copyInto(new Total());
    }
  
    protected Total copyInto(Total copyObj) throws TorqueException
    {
          copyObj.setTeethtotalID(teethtotalID);
          copyObj.setStudentID(studentID);
          copyObj.setTotalPerm(totalPerm);
          copyObj.setTotalSound(totalSound);
          copyObj.setTotalDecayed(totalDecayed);
          copyObj.setTotalMissing(totalMissing);
          copyObj.setTotalFilled(totalFilled);
          copyObj.setTotalDFM(totalDFM);
          copyObj.setTotalTemp(totalTemp);
          copyObj.setTotalTempSound(totalTempSound);
          copyObj.setTotalTempDecayed(totalTempDecayed);
          copyObj.setTotalTempFilled(totalTempFilled);
          copyObj.setTotalTempDFM(totalTempDFM);
          copyObj.setExamDate(examDate);
  
                    copyObj.setTeethtotalID(0);
                                                                                          
        
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public TotalPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Total:\n");
        str.append("TeethtotalID = ")
           .append(getTeethtotalID())
           .append("\n");
        str.append("StudentID = ")
           .append(getStudentID())
           .append("\n");
        str.append("TotalPerm = ")
           .append(getTotalPerm())
           .append("\n");
        str.append("TotalSound = ")
           .append(getTotalSound())
           .append("\n");
        str.append("TotalDecayed = ")
           .append(getTotalDecayed())
           .append("\n");
        str.append("TotalMissing = ")
           .append(getTotalMissing())
           .append("\n");
        str.append("TotalFilled = ")
           .append(getTotalFilled())
           .append("\n");
        str.append("TotalDFM = ")
           .append(getTotalDFM())
           .append("\n");
        str.append("TotalTemp = ")
           .append(getTotalTemp())
           .append("\n");
        str.append("TotalTempSound = ")
           .append(getTotalTempSound())
           .append("\n");
        str.append("TotalTempDecayed = ")
           .append(getTotalTempDecayed())
           .append("\n");
        str.append("TotalTempFilled = ")
           .append(getTotalTempFilled())
           .append("\n");
        str.append("TotalTempDFM = ")
           .append(getTotalTempDFM())
           .append("\n");
        str.append("ExamDate = ")
           .append(getExamDate())
           .append("\n");
        return(str.toString());
    }
}
